package com.richinfo.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by lenovo on 2020/5/9.
 * 修复版MD5工具类
 */
public class MD5 {
    public static String md5(String plainText) {
        byte[] secretBytes = null;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(
                    plainText.getBytes());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("没有md5这个算法！");
        }
        String md5code = new BigInteger(1, secretBytes).toString(16);// 16进制数字
        // 如果生成数字未满32位，需要前面补0
        int len = md5code.length();
        for (int i = 0; i < 32 - len; i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }
    public static void main(String[] args) {
//        String appkey = "28CED8FB5712C0D334C5B401C45E7D49";
//        String appId = "300011904398";
//        String scrip = "YW_7939C69A7B455A3A0672C9552DF8F2A15B203B1E8A3F742DABEA4BAF0BEA032F5D937D85ACB81B91726CF";
//        String msgId = "27ee4f6f-7aeb-4b4e-b6fc-4f8c524879da";
//        String timestamp = "20200224181559696";
////        System.out.println(md5(appId+scrip+msgId+timestamp+appkey));
        String token = "myTokeneyJhbGciOiJIUzI1NiIsInppcCI6IkRFRiJ9.eNqqViouTVKyUvJPLwh2jUgMrDAwMUo090tJd6zITky3tQ3Jz07NMzS1sLC0MDM2NjAyNgaLpKQamhiaKOkopVYUKFkB5S0NzI3MjQ1qAQAAAP__.980VPiDFCMWlcHL7x1Iekj4gvibLs-2Sqw24O4YZ4Vg";
//        String token = "myTokeneyJhbGciOiJIUzI1NiIsInppcCI6IkRFRiJ9.eNqqViouTVKyUkotM_TydMssjgzMzjJ2TypIi_RJrXS0tQ3Jz07NMzS1sDA3Mjc1MLEwNwCLmBimGKWaKukopVYUKFmB5C0MjS0NTGoBAAAA__8.7Fl46kr8OMCATg0GHy8Xp7R_nLMib_FuaJYr-ACWzL4";
        String yanzhi = "HTUA_ELIBOM";
        String md5code = md5(token+yanzhi);
        System.out.println(md5code);
        System.out.println(md5code.length());
    }
}
